<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            配件名称：<input type="text" name="partName"/>
                        </li>
                        <li>
                            领取人：<input type="text" name="receivePeople"/>
                        </li>
                        <li>
                            审批状态：
                            <select name="auditStatus">
                                <option value="">审批状态</option>
                                <option value="0">待审批</option>
                                <option value="1">通过</option>
                                <option value="2">驳回</option>
                            </select>
                        </li>
                        <li class="select-time">
                            <span>申请日期：</span>
                            <input type="text" style="width: 280px" class="time-input" id="startTime"
                                   name="createTime"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('business:partApplication:edit')}]];
    var removeFlag = [[${@permission.hasPermi('business:partApplication:remove')}]];
    var detailFlag = [[${@permission.hasPermi('business:inventoryRecord:detail')}]];
    var prefix = ctx + "business/partApplication";
    var prefix2 = ctx + "business/inventoryRecord";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "配件申请",
            search: false,
            showExport: true,
            columns: [{
                radio: true
            },
            {
                field: 'partId',
                title: '配件ID',
                visible: false
            },
            {
                title: "序号",
                formatter: function (value, row, index) {
                    return $.table.serialNumber(index);
                }
            },
            {
                field: 'projectName',
                title: '项目名称'
            },
            {
                field: 'partName',
                title: '配件名称'
            },
            {
                field : 'sizeName',
                title : '规格'
            },
            {
                field : 'priceName',
                title : '规格值'
            },
            {
                field: 'partTotal',
                title: '总量',
                sortable: true
            },
            {
                field: 'userId',
                title: '领取人ID',
                visible: false
            },
            {
                field: 'receivePeople',
                title: '领取人'
            },
            {
                field: 'receiveDate',
                title: '领取日期',
                visible: false
            },
            {
                field: 'receiveNum',
                title: '领取数量',
                sortable: true
            },
            {
                field: 'auditStatus',
                title: '审批状态',
                formatter: function (value, row, index) {
                    if (value == 0) {
                        return "待审批"
                    } else if (value == 1) {
                        return "通过"
                    } else if (value == 2) {
                        return "驳回"
                    }
                }
            },
            {
                field: 'createTime',
                title: '申请时间',
                sortable: true
            },
            {
                field: 'remark',
                title: '备注',
                formatter: function (value, row, index) {
                    return $.table.tooltip(value);
                }
            },
            {
                title: '操作',
                align: 'center',
                formatter: function(value, row, index) {
                    var actions = [];
                    if(row.auditStatus == 0){
                        actions.push('<a class="btn btn-success btn-xs ' + removeFlag + '" href="#" onclick="outBoundPass(\'' + row.partId + '\')"><i class="fa fa-check"></i>通过</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="outBoundRefuse(\'' + row.partId + '\')"><i class="fa fa-times"></i>拒绝</a> ');
                    }else if (row.auditStatus == 1) {
                        actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="#" onclick="passDetail(\'' + row.partId + '\')"><i class="fa fa-search"></i>查看详情</a> ');
                    }else if (row.auditStatus == 2){
                        actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="#" onclick="outBoundRefuseReason(\'' + row.partId + '\')"><i class="fa fa-search"></i>拒绝原因</a> ');
                    }
                    return actions.join('');
                }
            }]
        };
        $.table.init(options);
    });

    /* 出库-通过 */
    function outBoundPass(recordId) {
        var url = prefix2 + "/outBoundPass/"+recordId;
        $.modal.open("审核通过", url, '500', '300');
    }

    /* 出库-拒绝 */
    function outBoundRefuse(recordId) {
        var url = prefix2 + "/outBoundRefuse/"+recordId;
        $.modal.open("审核拒绝", url, '500', '300');
    }

    /* 拒绝原因 */
    function outBoundRefuseReason(recordId) {
        var options = {
            title: "拒绝原因",
            width: '500',
            height: '300',
            url:  prefix2 + "/outBoundRefuseReason/"+recordId,
            skin: 'layui-layer-gray',
            btn: ['关闭'],
            yes: function (index, layero) {
                layer.close(index);
            }
        };
        $.modal.openOptionsNotConfirmBtn(options);
    }

    /* 查看详情 */
    function passDetail(recordId) {
        var options = {
            title: "查看详情",
            width: '800',
            height: '600',
            url:  prefix2 + "/passDetail/"+recordId,
            skin: 'layui-layer-gray',
            btn: ['关闭'],
            yes: function (index, layero) {
                layer.close(index);
            }
        };
        $.modal.openOptionsNotConfirmBtn(options);
    }
</script>
</body>
</html>